package com.campus.controller;

import com.campus.entry.ManagerTeacher;
import com.campus.exception.BusinessException;
import com.campus.pojo.dto.TeacherDto;
import com.campus.response.ResponseResult;
import com.campus.response.ResultCode;
import com.campus.service.ManagerTeacherService;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

@RestController
@RequestMapping("/teacher")
public class ManagerTeacherController {
    @Autowired
    private ManagerTeacherService managerTeacherService;
    @PostMapping("/save")
    public ResponseResult<Object> saveTeacher(@RequestBody ManagerTeacher managerTeacher){
        if (Objects.isNull(managerTeacher.getTeacherName())){
            throw new BusinessException(ResultCode.ERROR);
        }
        managerTeacherService.saveTeacher(managerTeacher);
        return new ResponseResult<>(ResultCode.ALL_SUCCESS,null);
    }
    @GetMapping("/getById")
    public ResponseResult<ManagerTeacher> getTeacherById(@RequestParam Integer managerTeacherId){
        if (Objects.isNull(managerTeacherId)){
            throw new BusinessException(ResultCode.ERROR);
        }
        ManagerTeacher teacherById = managerTeacherService.getTeacherById(managerTeacherId);
        return new ResponseResult<>(ResultCode.ALL_SUCCESS,teacherById);
    }
    @GetMapping("/getBy")
    private ResponseResult<List<ManagerTeacher>> getTeacherBy(@RequestBody TeacherDto teacherDto){
        List<ManagerTeacher> list=managerTeacherService.getTeacherBy(teacherDto);
        return new ResponseResult<>(ResultCode.ALL_SUCCESS,list);
    }
}
